package com.lanhe.pay.controller;

import cn.hutool.core.util.ObjectUtil;
import com.lanhe.common.core.controller.BaseController;
import com.lanhe.common.core.domain.AjaxResult;
import com.lanhe.common.utils.zhifubao.vo.ZhiFuBaoPayNotifyDataVo;
import com.lanhe.order.domain.LhOrdersLevel;
import com.lanhe.order.service.ILhOrdersLevelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



/**
 * 支付宝支付
 *
 * @author zhanggl
 * @date 2024/1/5
 */
@Slf4j
@RestController
@RequestMapping("/api/aliPay")
public class ZhiFuBaoPayController extends BaseController {

    @Autowired
    private ILhOrdersLevelService ordersLevelService;


    /**
     * 下单
     *
     * @param level 实体
     * @author tianliang
     * @date 2024/1/21
     */
    @PostMapping("/pay")
    public AjaxResult pay(@RequestBody LhOrdersLevel level) {
        if (ObjectUtil.isNull(level.getLevelId())) {
            return error("请选择要购买的VIP产品");
        }
        if (ObjectUtil.isNull(level.getOrderType())) {
            return error("请标识订单类型");
        }
        level.setMemberId(getUserId());
        return success(ordersLevelService.insertOrdersLevelPayALi(level));
    }

    /**
     * 支付宝支付回调
     *
     * @param notifyDataVo 返回数据
     * @author tianliang
     * @date 2024/1/21
     */
    @PostMapping(value="notify")
    public String notify(ZhiFuBaoPayNotifyDataVo notifyDataVo ) {

        log.info("支付宝支付回调数据:{}", notifyDataVo);
        System.err.println("notifyDataVo "+notifyDataVo);
        ordersLevelService.notifyZhiFuBaoOrdersLeve(notifyDataVo);
        return "success";
    }

}
